package com.zlx.sharelive.activity;

import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import com.zlx.module_base.base_ac.BaseAc;
import com.zlx.module_base.base_api.res_data.BaseBean;
import com.zlx.module_base.base_api.res_data.DeleteFriendBean;
import com.zlx.module_base.base_api.util.ApiUtil;
import com.zlx.module_base.base_util.SPUtil;
import com.zlx.module_network.api1.livedata.BaseObserver;
import com.zlx.module_network.api1.livedata.BaseObserverCallBack;
import com.zlx.module_network.bean.ApiResponse;
import com.zlx.sharelive.R;
import com.zlx.sharelive.utils.StringUt;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 添加伴侣
 */
public class AddCompanionAc extends BaseAc {

    @BindView(R.id.et_mate_id)
    EditText et_mate_id;

    @Override
    protected int getLayoutId() {
        return R.layout.ac_add_companion;
    }

    @Override
    public void initViews() {
        super.initViews();


    }

    @OnClick({R.id.bt_certain, R.id.iv_back})
    public void setOnClick(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.bt_certain:
                if (StringUt.isEmpty(et_mate_id.getText().toString().trim())) {
                    Toast.makeText(this, "伴侣ID不可为空", Toast.LENGTH_SHORT).show();
                    return;
                } else {
                    DeleteFriendBean bean = new DeleteFriendBean();
                    bean.setId(et_mate_id.getText().toString().trim());
                    ApiUtil.getUserApi().addOrDeleteFriend(SPUtil.getToken(this),
                            bean).observe(this, new BaseObserver<>(new BaseObserverCallBack<ApiResponse<BaseBean>>() {
                        @Override
                        public void onSuccess(ApiResponse<BaseBean> data) {
                            if (null != data) {
                                if (null != data.getData()) {
                                    if (data.getData().getCode() == 0) {
                                        Toast.makeText(AddCompanionAc.this, "已申请，等待对方同意", Toast.LENGTH_SHORT).show();
                                        finish();
                                    } else {
                                        Toast.makeText(AddCompanionAc.this, data.getData().getMsg(), Toast.LENGTH_SHORT).show();
                                    }
                                }
                            }

                        }

                        @Override
                        public void onFinish() {
                            super.onFinish();

                        }
                    }));
                }
                break;
        }
    }
}
